<template>
	<view class="container">
		<view class="content">
			<view class="title">{{queryData.title}}</view>
			<view class="title">组别：</view>
			<view class="uni-list">
				<radio-group @change="radioChange1">
					<label style="transform: translateX(35%);padding: 5px;font-size:20px;" class="uni-list-cell uni-list-cell-pd" v-for="(item,index) in array" :key="index">
						<view>
							<radio :value="item.groupType" />
						</view>
						<view style="font-size:16px;">{{item.name}}</view>
					</label>
				</radio-group>
			</view>
			<view class="title">科目：</view>
			<view class="uni-list">
				<radio-group  @change="radioChange2">
					<label style="transform: translateX(35%);padding: 5px;font-size:20px;" class="uni-list-cell uni-list-cell-pd" v-for="(item,index) in projectArray" :key="item.id">
						<view>
							<radio :value="index" />
						</view>
						<view style="font-size:16px;">{{item.name}}</view>
					</label>
				</radio-group>
			</view>
			
		</view>
		<view class="btn">
			<button style="width: 100px;font-size: 18px;margin-top: 20px;font-size: 16px;"  @click="queryGrade">排行查询</button>
			<button v-show="flag" style="width: 100px;font-size: 18px;margin-top: 10px;margin-bottom: 20px;font-size: 16px;" @click="postGrade">成绩录入</button>
		</view>
	</view>
</template>
<script>
	import {projects,usersRole} from '../../apis'
	export default {
		data() {
			return {
				array: [{
						name: '小学组',
						groupType: '1'
					}, {
						name: '初中组',
						groupType: '2'
					}, {
						name: '高中组',
						groupType: '3'
					},
					{
						name: '大学组',
						groupType: '4'
					},{
						name: '附加组',
						groupType: '5'
					}
				],
				projectArray:[],
				queryData:{
					projectId:'-1',
					projectName:'',
					competitionId:0,
					groupTypeEnum:'XIAOXUE',
					title: '',
					gradeType:0
				},
				groupType: 0,
				flag:false,
				projectValue:-1
			}
		},
		onLoad(option) {
			uni.showLoading({
			    title: '加载中'
			});
			console.log("前面传的值为："+option)
			this.queryData.competitionId = option.id,
			this.queryData.title = option.title,
			
			projects({
				"competitionId":option.id
			}).then((res)=>{
				let [err,data] = res
				this.projectArray = data.data.data
				console.log("项目数据为："+JSON.stringify(data.data.data))
				uni.hideLoading();
			})
			usersRole().then((res)=>{
				let [err,data] = res
				console.log("用户信息为："+JSON.stringify(data.data.data))
				if(data.data.data == "admin"){
					this.flag = true
				}
				if(data.data.data == "teacher"){
					this.flag = true
				}
			})
		},
		methods: {
			radioChange1: function(e) {
				console.log(e)
				console.log("获得组别："+e.detail.value)
				this.groupType=e.detail.value
				//this.queryData.groupTypeEnum = e.detail.value
					if(e.detail.value == 1){
						this.queryData.groupTypeEnum = "XIAOXUE"
					}else if(e.detail.value == 2){
						this.queryData.groupTypeEnum = "CHUZHONG"
					}else if(e.detail.value == 3){
						this.queryData.groupTypeEnum = "GAOZHONG"
					}else if(e.detail.value == 4){
						this.queryData.groupTypeEnum = "DAXUE"
					}else{
						this.queryData.groupTypeEnum = "FUJIA"
					}
				// this.flag1 = false
				console.log(this.queryData.groupTypeEnum)
			},
			radioChange2: function(e) {
				// console.log("复选框携带的值"+JSON.stringify(this.projectArray[e.detail.value]))
				this.projectValue = e.detail.value
				this.queryData.projectId = this.projectArray[e.detail.value].id
				this.queryData.projectName = this.projectArray[e.detail.value].name
				this.queryData.gradeType = this.projectArray[e.detail.value].gradeType
			},
			queryGrade() {
				console.log(this.groupType)
				console.log(this.projectValue)
				if(this.groupType==0){
					uni.showToast({
						title:'选择组别和科目',
						duration:3000,
						image:'../../static/gantan.png'
					})
				}else if(this.projectValue==-1){
					uni.showToast({
						title:'选择组别和科目!',
						duration:3000,
						image:'../../static/gantan.png'
					})
				}else{
					uni.navigateTo({
						url: '../querylist/querylist?queryData='+JSON.stringify(this.queryData)
					});
				}
			},
			postGrade() {
				if(this.groupType==0){
					uni.showToast({
						title:'请选择组别!',
						duration:3000,
						image:'../../static/gantan.png'
					})
				}else{
					uni.navigateTo({
					    url: '../postgrade/postgrade?competitionId='+this.queryData.competitionId+'&title='+this.queryData.title+'&groupType='+this.groupType
					});
				}
			}
		}
	}
</script>

<style lang="scss" scoped>
	.content{
		width: 90%;
		margin: 0 auto;
		.title,
		.bot,
		.btn{
			margin-top: 10px;
			font-weight: bold;
		}
		.title{
			text-align: center;
			font-size: 18px;
			font-weight: bold;
		}
		
	}
</style>
